package Thread.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class PoolTimer {
    public static void main(String[] args) {
       ScheduledExecutorService executor= Executors.newScheduledThreadPool(3);//工具类创建线程池,缺点很多,建议项目中不使用
        executor.scheduleWithFixedDelay(()->{//基于线程池的定时器 弥补了Timer的不足
            System.out.println("执行A...");
            System.out.println(10/0);
            try {
                Thread.sleep(10*1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },1,3, TimeUnit.SECONDS);
        executor.scheduleWithFixedDelay(()->{
            System.out.println("执行B...");
        },1,3, TimeUnit.SECONDS);
        executor.scheduleWithFixedDelay(()->{
            System.out.println("执行C...");
        },1,3, TimeUnit.SECONDS);
    }
}
